public class BinaryTree {

    static class TreeNode {
        public char val;
        //存储左孩子节点的引用
        public TreeNode left;
        //存储右孩子节点的引用
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }


    public TreeNode createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');

        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        E.right = H;

        return A;
    }

    //前序遍历
    public void Qbianli(TreeNode root) {
        if(root == null) {
            return;
        }
        System.out.print(root.val+" ");
        Qbianli(root.left);
        Qbianli(root.right);
    }

    //中序遍历
    public void Zbianli(TreeNode root) {
        if(root == null) {
            return;
        }
        Zbianli(root.left);
        System.out.print(root.val+" ");
        Zbianli(root.right);
    }
    //后序遍历
    public void Hbianli(TreeNode root) {
        if(root == null) {
            return;
        }
        Hbianli(root.left);
        Hbianli(root.right);
        System.out.print(root.val+" ");
    }

    //计算节点个数方法一
    public int count = 0;
    public int size1(TreeNode root) {
        if(root == null) {
            return 0;
        }
        count++;
        size1(root.left);
        size1(root.right);
        return count;
    }

    //计算节点个数方法二
    public int size2(TreeNode root) {
        if(root == null) {
            return 0;
        }
        return size2(root.left) + size2(root.right) + 1;
    }

    //计算叶子个数方法一
    public int ye = 0;
    public int sizeye1(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right == null) {
            ye++;
        }
        sizeye1(root.left);
        sizeye1(root.right);
        return ye;
    }

    //计算叶子个数方法二
    public int sizeye2(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right == null) {
            return 1;
        }
        return sizeye2(root.left) + sizeye2(root.right);

    }

    //计算树第k层节点个数
    public int tree(TreeNode root,int k) {
        if(root == null) {
            return 0;
        }
        if(k==1) {
            return 1;
        }
        return tree(root.left,k-1) + tree(root.right,k-1);
    }

    //计算树的钱高度
    public int Hight(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int left = Hight(root.left);
        int right = Hight(root.right);
        return left > right ?  left + 1 : right + 1 ;
    }

//    public TreeNode find(TreeNode root,int val) {
//        if(root == null) {
//            return null;
//        }
//        if(root.val == val) {
//            return root;
//        }
//        return find(root.left);
//        return find(root.right);
//
//    }

//    if(root==null) {
//        return null;
//    }
//    TreeNode k = null;
//    k = root.left;
//    root.left



}